import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Stack;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-05-10
 * Time:16:23
 */

/**
 * BM44 有效括号序列
 */

public class isValid {
    public static void main(String[] args) {
        System.out.println(isValid("{[()]}"));
    }
    //(',')','{','}','['和']'
    public static boolean isValid (String s) {
        // write code here
        Stack<Character> stack = new Stack<>();
        for(char c:s.toCharArray()){
            if(c =='(')
                stack.push(')');
            else if(c =='[')
                stack.push(']');
            else if(c =='{')
                stack.push('}');
            else if(stack.empty()||stack.pop()!=c)
                return false;
        }
        return stack.empty();

    }
}
